<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增试卷题目</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('ach_exam_paper_questions_item')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ach-exam-paper-questions-item-modal ref="modalForm" @ok="modalFormOk"></ach-exam-paper-questions-item-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AchExamPaperQuestionsItemModal from './modules/AchExamPaperQuestionsItemModal'
  import { getAction } from '@api/manage'

  export default {
    name: 'AchExamPaperQuestionsItemList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      AchExamPaperQuestionsItemModal
    },
    data () {
      return {
        description: 'ach_exam_paper_questions_item管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'所属试卷',
            align:"center",
            dataIndex: 'examinationPaperName'
          },
          {
            title:'试卷题型',
            align:"center",
            dataIndex: 'examPaperProjectItemName'
          },
          {
            title:'试题类型',
            align:"center",
            dataIndex: 'exaPapQueItemTtype_dictText'
          },
          // {
          //   title:'题库试题',
          //   align:"center",
          //   dataIndex: 'questionBankItemId'
          // },
          {
            title:'题库试题',
            align:"center",
            dataIndex: 'questionBankItemName'
          },
          {
            title:'题号',
            align:"center",
            dataIndex: 'exaPapQueItemNo'
          },
          {
            title:'试题满分',
            align:"center",
            dataIndex: 'exaPapQueItemFullMarks'
          },
          {
            title:'显示顺序',
            align:"center",
            sorter: true,
            dataIndex: 'exaPapQueItemOrder'
          },
          {
            title:'建议用时(分钟)',
            align:"center",
            dataIndex: 'proposalDuration'
          },
          {
            title:'是否启用',
            align:"center",
            dataIndex: 'izOpen_dictText'
          },
          // {
          //   title:'所属部门',
          //   align:"center",
          //   dataIndex: 'sysOrgName'
          // },
          // {
          //   title:'是否删除',
          //   align:"center",
          //   dataIndex: 'delFlag_dictText'
          // },
          // {
          //   title:'创建人',
          //   align:"center",
          //   dataIndex: 'createBy'
          // },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          // {
          //   title:'修改人',
          //   align:"center",
          //   dataIndex: 'updateBy'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          // list123: "/achexampaperquestionsitem/achExamPaperQuestionsItem/list",
          questionItemList: "/achexampaperquestionsitem/achExamPaperQuestionsItem/voList",
          delete: "/achexampaperquestionsitem/achExamPaperQuestionsItem/delete",
          deleteBatch: "/achexampaperquestionsitem/achExamPaperQuestionsItem/deleteBatch",
          exportXlsUrl: "/achexampaperquestionsitem/achExamPaperQuestionsItem/exportXls",
          importExcelUrl: "achexampaperquestionsitem/achExamPaperQuestionsItem/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        //条件查询参数
        serchParams: {
          // id: null,
          // subjectId: null,
          // examinationPaperId: null,
          // exaPapProItemCode: null,
          // exaPapProItemName: null,
          // exaPapProItemFullMarks: null,
          // exaPapProItemTtype: null,
          // exaPapProItemSubTtype: null,
          // exaPapProItemLevel: null,
          // exaPapProItemFatherId: null,
          // exaPapProItemOrder: null,
          // izOpen: null,
          // sysOrgCode: null,
          // tenantId: null,
          // delFlag: null,
          // createBy: null,
          // createTime: null,
          // updateBy: null,
          // updateTime: null,
        },
        objectModel: {
          id: null
        },
      }
    },
    created() {
    this.getSuperFieldList();
    this.getOrderMain();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'examinationPaperId',text:'试卷id',dictCode:''})
        fieldList.push({type:'string',value:'examPaperProjectItemId',text:'所属分项id',dictCode:''})
        fieldList.push({type:'string',value:'exaPapQueItemTtype',text:'试题类型（1单选 2多选  3简答 4填空 5判断 6阅读 7完型填空 8实验 9手工制作） ',dictCode:''})
        fieldList.push({type:'string',value:'questionBankItemId',text:'题库试题id',dictCode:''})
        fieldList.push({type:'string',value:'exaPapQueItemNo',text:'试题编号',dictCode:''})
        fieldList.push({type:'double',value:'exaPapQueItemFullMarks',text:'试题满分',dictCode:''})
        fieldList.push({type:'double',value:'proposalDuration',text:'考试建议时长(分钟)',dictCode:''})
        fieldList.push({type:'int',value:'izOpen',text:'是否启用(1是启用，0否停用)',dictCode:''})
        fieldList.push({type:'string',value:'sysOrgCode',text:'所属部门编码',dictCode:''})
        fieldList.push({type:'string',value:'tenantId',text:'学校id',dictCode:''})
        fieldList.push({type:'int',value:'delFlag',text:'0表示未删除,1表示删除',dictCode:''})
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        fieldList.push({type:'date',value:'createTime',text:'创建时间'})
        fieldList.push({type:'string',value:'updateBy',text:'修改人',dictCode:''})
        fieldList.push({type:'string',value:'exaPapQueItemOrder',text:'试题顺序',dictCode:''})
        this.superFieldList = fieldList
      },
      loadData(arg) {
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        //update-begin--Author:kangxiaolin  Date:20190905 for：[442]主子表分开维护，生成的代码子表的分页改为真实的分页--------------------
        var params = this.getQueryParams();
        getAction(this.url.questionItemList, {examinationPaperId: params.mainId, pageNo : this.ipagination.current,
          pageSize :this.ipagination.pageSize}).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          } else {
            this.dataSource = null;
          }
        })
        //update-end--Author:kangxiaolin  Date:20190905 for：[442]主子表分开维护，生成的代码子表的分页改为真实的分页--------------------

      },

      getOrderMain(record) {
        //其中objectParam中包含AchExaminationPaperList中已选的一条完整试卷数据
        this.queryParam.mainId = record.id;
        this.loadData(1);
        this.objectModel = record //将试卷AchExaminationPaperList选择的试卷数据record，赋值给objectModel
      },
      handleAdd: function () {
        if (this.objectModel.id === null || this.objectModel.id === ""){
          return alert("请先选择要添加试题的试卷");
        }
        // this.$refs.modalForm.add(this.queryParam.mainId);
        this.$refs.modalForm.title = "添加试卷题目信息";
        this.$refs.modalForm.add(this.objectModel) //objectModel包含的是当前选择试卷数据
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>